package com.smart.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smart.global.GlobalWord;
import com.smart.pojo.OutboundBill;
import com.smart.mapper.OutboundBillMapper;
import com.smart.resp.LeaveBillResp;
import com.smart.resp.OutboundBillResp;
import com.smart.service.IOutboundBillService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lyj
 * @since 2023-05-17
 */
@Service
public class OutboundBillServiceImpl extends ServiceImpl<OutboundBillMapper, OutboundBill> implements IOutboundBillService {

    @Autowired
    private TaskService taskService;

    @Override
    public void queryPage(Page<OutboundBillResp> page) {
        baseMapper.queryPage(page);
        for (OutboundBillResp outboundBillResp : page.getRecords()) {
            String businessKey = GlobalWord.OUTBOUND_KEY + "." + outboundBillResp.getId();
            Task task = taskService.createTaskQuery().processInstanceBusinessKey(businessKey).singleResult();

            outboundBillResp.setTaskName(task == null ? "已结束" : task.getName());

        }
    }

    @Override
    public OutboundBillResp queryByBillId(long id) {
        return baseMapper.queryByBillId(id);
    }
}
